<!-- 业务收款 -->
<template>
  <div class="collection-list">
    <div ref="dgtools" class="filter-container">
      <div class="dgts-row">
        <b class="tr-it">收款总价:{{ getCollTotalPrice || 0.0 }}</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">已收总价:{{ getalGathPrice || 0.0 }}</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">应收余额:{{ (getCollTotalPrice - getalGathPrice).toFixed(2) || 0.0 }}</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">旅网总价:{{ gettravelPrepayPrice || 0.0 }}</b>
        <el-divider direction="vertical"></el-divider>
        <b class="tr-it">自网总价:{{ getselfPrepayPrice || 0.0 }}</b>
      </div>

      <div class="dgts-fm">
        <el-select
          clearable filterable
          remote reserve-keyword
          :remote-method="queryCusPageList"
          style="width: 140px"
          v-model="dg.ps.customId"
          placeholder="用车单位">
          <el-option
            v-for="it in cusOptions"
            :key="it.baseUserId.uname"
            :label="it.unitName"
            :value="it.id"
            @click.native="queryLinkManList(it)">
            <span>{{it.unitName}}</span>
            <span>{{it.baseUserId.realName}}</span>
          </el-option>
        </el-select>

        <el-select
          v-model="dg.ps.dutyService"
          clearable filterable
          :placeholder="'联系人'"
          style="width: 120px">
          <el-option
            v-for="(it, i) in linkManList"
            :key="i"
            :label="it.realName"
            :value="it.uname">
            <span>{{it.realName}}</span>
            <span>{{it.phone}}</span>
          </el-option>
        </el-select>

        <el-select
          v-model="dg.ps.serviceMan"
          clearable
          filterable
          :disabled="serviceManList.length === 0"
          :placeholder="serviceManList.length === 0 ? '数据加载中...' : '业务员'"
          style="width: 100px">
          <el-option
            v-for="it in serviceManList"
            :key="it.baseUserId.uname"
            :label="it.baseUserId.realName"
            :value="it.baseUserId.uname">
            <span>{{it.baseUserId.realName}}</span>
            <span>{{it.baseUserId.phone}}</span>
          </el-option>
        </el-select>

        <el-select
          v-model="dg.ps.payStatus"
          :placeholder="'订单支付状态'"
          style="width: 120px"
          clearable>
          <el-option :label="'未收款'" :value="'UNPAID'"></el-option>
          <el-option :label="'已付定金'" :value="'DEPOSIT_PAID'"></el-option>
          <el-option :label="'全款已付'" :value="'FULL_PAID'"></el-option>
        </el-select>

        <el-select
          v-model="dg.ps.gathLock"
          :placeholder="'收款锁定'"
          style="width: 100px"
          clearable>
          <el-option :label="'未锁定'" :value="'UNLOCK'"></el-option>
          <el-option :label="'已锁定'" :value="'LOCKED'"></el-option>
        </el-select>

        <el-select
          v-model="dg.ps.timeType"
          :placeholder="'时间类型'"
          style="width: 100px"
          clearable>
          <el-option :label="'用车时间'" :value="1"></el-option>
          <el-option :label="'下单时间'" :value="2"></el-option>
          <el-option :label="'续团时间'" :value="3"></el-option>
        </el-select>

        <el-date-picker
          v-model="dg.ps.startTime"
          placeholder="开始日期"
          value-format="yyyy-MM-dd"
          style="width: 125px"
        />
        <el-date-picker
          v-model="dg.ps.endTime"
          placeholder="结束日期"
          value-format="yyyy-MM-dd"
          style="width: 125px"
        />

        <el-select
          v-model="dg.ps.driver"
          clearable
          filterable
          placeholder="请选择驾驶员"
          style="width: 120px">
          <el-option
            v-for="it in driverOptions"
            :key="it.uname"
            :label="it.realName"
            :value="it.uname">
          </el-option>
        </el-select>

        <el-input
          clearable
          style="width: 100px"
          placeholder="车牌号"
          v-model="dg.ps.plateNum">
        </el-input>

        <el-input
          clearable
          style="width: 140px"
          placeholder="订单号"
          v-model="dg.ps.orderNum">
        </el-input>

        <!-- <el-input
          style="width: 140px"
          placeholder="凭证号"
          v-model="dg.ps.voucherNumFind">
        </el-input> -->

        <el-input
          clearable
          style="width: 140px"
          placeholder="行程详情"
          v-model="dg.ps.routeDetail">
        </el-input>

        <el-select
          v-model="dg.ps.compositor"
          :placeholder="'排序'"
          style="width: 80px"
          clearable>
          <el-option :label="'降序'" :value="'DESC'"></el-option>
          <el-option :label="'升序'" :value="'ASC'"></el-option>
        </el-select>

        <el-select
          v-model="dg.ps.isSelf"
          :placeholder="'车辆是否自营'"
          style="width: 120px"
          clearable>
          <el-option :label="'是'" :value="0"></el-option>
          <el-option :label="'否'" :value="1"></el-option>
        </el-select>

        <el-input
          style="width: 150px"
          placeholder="操作号"
          v-model="dg.ps.operMark"
        />

        <el-button 
          type="primary" 
          icon="el-icon-search" 
          @click="getDgList">
          搜索
        </el-button>

        <div>
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="setBusinessCollectionMd({state: true})">
            收业务款
          </el-button>

          <el-button
            type="primary"
            icon="el-icon-close"
            @click="setCollectionRecordMd({state: true})">
            撤销收款
          </el-button>

          <el-button
            type="primary"
            icon="el-icon-close"
            @click="cancelConfirmCollection">
            取消收款锁定
          </el-button>
          
          <el-button 
            type="primary" 
            icon="el-icon-edit-outline" 
            @click="setBackPaymentMd({state: true})">
            平账
          </el-button>

          <el-button 
            type="primary" 
            icon="el-icon-close" 
            @click="setCancelBackPaymentMd({state: true})">
            撤销平账
          </el-button>
          
          <el-button 
            type="primary" 
            icon="el-icon-bottom" 
            @click="handleExport">
            导出
          </el-button>
        </div>
      </div>

      <TableSelfSet
        v-if="dg.columns.length > 0"
        :tbTitle="'业务收款'"
        :dgName="dg.dgName"
        :tbId="dg.tbName"
        :srcCols="dg.srcCols"
        :columns="dg.columns"
        :showSeledInfo="this"
        @saveSet="saveTbSet"
      />
    </div>

    <el-table
      :ref="dg.tbName"
      :data="dg.list"
      row-key="id"
      border fit
      :height="bodyHeight"
      :row-class-name="rowClassName"
      @header-dragend="dragHeader"
      @selection-change="selRowChange">
      <el-table-column fixed="left" type="index" label="编号" width="40" align="center" :resizable="false"></el-table-column>
      <el-table-column fixed="left" type="selection" width="40" align="center" :resizable="false"></el-table-column>
      <fragment v-for="col in dg.columns" :key="col.field">
        <el-table-column
          :class-name="dg.dgName"
          :prop="col.field"
          :label="col.label"
          :width="col.width">
          <template slot-scope="{ row }">
            <template v-if="col.field == 'status'">
              {{getCarTypeText(row.status)}}
            </template>

            <template v-else-if="col.field == 'serviceType'">
              {{getServericTypeText(row.serviceType)}}
            </template>

            <template v-else-if="col.field == 'payStatus'">
              {{getServiceType(row.payStatus)}}
            </template>

            <template v-else-if="col.field == 'gathLock'">
              {{getLockText(row.gathLock)}}
            </template>

            <template v-else-if="col.field == 'isSplit'">
              {{row.isSplit == 0 ? "否" : "是"}}
            </template>

            <template v-else-if="col.field == 'needInfo'">
              <el-tooltip
                class="item"
                effect="dark"
                :content="row.tips"
                placement="top-start">
                <span>{{ row.needInfo }}</span>
              </el-tooltip>
            </template>

            <template v-else-if="col.field == 'allPlateNum'">
              <div v-for="(o, i) in row.driverInfo" :key="i">{{o.plateNum}}</div>
            </template>

            <template v-else-if="col.field == 'allDriver'">
              <div v-for="(o, i) in row.driverInfo" :key="i">{{ o.realName && o.realName+'（'+o.phone+'）'}}</div>
            </template>

            <template v-else-if="col.field == 'cusNote'">
              <div v-for="(o, i) in row.cusNote" :key="i">{{o}}</div>
            </template>

            <template v-else-if="col.field == 'driverNote'">
              <div v-for="(o, i) in row.driverNote" :key="i">{{o}}</div>
            </template>

            <template v-else-if="col.field == 'serviceNote'">
              <div v-for="(o, i) in row.serviceNote" :key="i">{{o}}</div>
            </template>
            
            <template v-else-if="col.field == 'routeDetail'">
              <div v-for="(o, i) in row.routeDetail" :key="i">{{(row.routeDetail.length > 1 ? (i+1)+'、' : '')+o}}</div>
            </template>

            <template v-else-if="col.field == 'restMoney'">
              <span v-if="row.restMoney >= 0">{{row.restMoney}}</span>
              <b v-else class="c-red">{{row.restMoney}}</b>
            </template>

            <template v-else-if="col.field == 'operNote'">
              <span v-html="row.operNote.replace(/\(/g, '<br />').replace(/\)/g, '；<br />').replace(/&nbsp;,/g, '<br />')"></span>
            </template>

            <template v-else>{{ getColVal(row, col.field) }}</template>
          </template>
        </el-table-column>
      </fragment>
    </el-table>
    <Pagination
      v-show="dg.total > 0"
      :total="dg.total"
      :page.sync="dg.ps.page"
      :limit.sync="dg.ps.rows"
      @pagination="getDgList"
    />

    <BusinessCollection
      v-if="businessCollectionMd.state"
      :myData="businessCollectionMd"
      @myClick="setBusinessCollectionMd"
      @reloadDg="getDgList"
    />

    <CollectionBackPayment
      v-if="backPaymentMd.state"
      :myData="backPaymentMd"
      @myClick="setBackPaymentMd"
      @reloadDg="getDgList"
    />

    <CancelCollectionBackPayment
      v-if="cancelBackPaymentMd.state"
      :myData="cancelBackPaymentMd"
      @myClick="setCancelBackPaymentMd"
      @reloadDg="getDgList"
    />

    <CollectionRecord
      v-if="collectionRecordMd.state"
      :myData="collectionRecordMd"
      @myClick="setCollectionRecordMd"
      @reloadDg="getDgList"
    />

  </div>
</template>

<script>
import DataGridBase from "@/views/mixins/DataGridBase";
import DataGridResize from "@/views/mixins/DataGridResize";
import elDragDialog from "@/directive/el-drag-dialog";
import TableSelfSet from "@/components/TableSelfSet";
import Pagination from "@/components/Pagination";

import { exportExcel } from "@/utils/exportFile";
import * as orderSer from "@/api/services/order.service";
import * as commonSer from "@/api/services/common.service";

import BusinessCollection from "./business-collection";
import CollectionRecord from './collection-record';
import CollectionBackPayment from "./collection-back-payment";
import CancelCollectionBackPayment from "./cancel-collection-back-payment";

export default {
  name: "CollectionList",
  mixins: [DataGridBase, DataGridResize],
  directives: { elDragDialog },
  components: {
    TableSelfSet, 
    Pagination, 
    BusinessCollection, 
    CollectionRecord, 
    CollectionBackPayment, 
    CancelCollectionBackPayment 
  },
  data() {
    let cols = [
      { label: "主订单编号", field: "orderNum", width: 120 },
      { label: "用车状态", field: "status", width: 80 },
      { label: "驾驶员", field: "allDriver", width: 150 },
      { label: "车牌号", field: "allPlateNum", width: 80 },
      { label: "开始日期", field: "sd", width: 80 },
      { label: "开始时间", field: "st", width: 65 },
      { label: "结束日期", field: "ed", width: 80 },
      { label: "结束时间", field: "et", width: 65 },
      { label: "业务员", field: "serviceMan", width: 80 },
      { label: "客户", field: "customId", width: 100 },
      { label: "客户备注", field: "cusNote", width: 150 },
      { label: "驾驶员备注", field: "driverNote", width: 150 },
      { label: "行程详情", field: "routeDetail", width: 400 },
      { label: "车辆数", field: "needCars", width: 60 },
      { label: "实派车", field: "needInfo", width: 100 },
      { label: "其他费用", field: "otherPrice", width: 100 },
      { label: "提醒现收", field: "remDriverCharge", width: 100 },
      { label: "收款价格", field: "price", width: 100 },
      // { label: "派单应收", field: "handSelPrice", width: 100 },
      { label: "已收金额(元)", field: "alGathPrice", width: 100 },
      { label: "旅网金额", field: "travelPrepayPrice", width: 100 },
      { label: "自网金额", field: "selfPrepayPrice", width: 100 },
      { label: "应收余额", field: "restMoney", width: 100 },
      { label: "订单业务类型", field: "serviceType", width: 100 },
      { label: "订单支付状态", field: "payStatus", width: 100 },
      { label: "收款锁定", field: "gathLock", width: 100 },
      { label: "操作编号", field: "operMark", width: 150 },
      { label: "是否拆分", field: "isSplit", width: 80 },
      { label: "财务备注", field: "operNote", width: 230 },
    ];

    return {
      dg: {
        dgName: "dg",
        tbName: "collectionListTb",
        total: 0,
        list: [],
        srcCols: cols,
        columns: [],
        selRows: [],
        ps: {
          // 过滤参数
          page: 1, rows: 100,
          find: "",
          /** 车辆是否自营  */
          isSelf: "",
          /** 时间顺序  */
          compositor: "",
          /** 客户（用车方）  */
          customId: "",
          /** 应该收余额 */
          money: "",
          /** 订单号*/
          orderNum: "",
          /** 驾驶员uname  */
          driver: "",
          /** 用车方负责人  */
          dutyService: "",
          /** 结束时间  */
          endTime: "",
          /** 订单支付状态  */
          payStatus: "",
          /** 车牌号  */
          plateNum: "",
          /** 业务员  */
          serviceMan: "",
          /** 开始时间  */
          startTime: "",
          /** 搜索时间类型 */
          routeGath: "", // 现收金额
          timeType: "",
          routeDetail: "",
          /** 凭证号 */
          voucherNum: "",
          gathLock: "",
          /** 确认收款价格 */
          isConfirmGath: "",
          // 操作编号
          operMark: "", 
        },
        allPrice: {
          nogath: "",
          totalPrice: "",
          totalAlGath: "",
          travelPrepayPrice: "",
          selfPrepayPrice: "",
        },
      },

      // 业务收款-弹框
      businessCollectionMd: {state: false},
      // 平账-弹框
      backPaymentMd: {state: false},
      // 撤销平账-弹框
      cancelBackPaymentMd: {state: false},
      // 收款记录-弹框
      collectionRecordMd: {state: false},

      allCusList: [],
      driverOptions: [],
      clientList: [],
      partunitList: [],
      // 订单状态数组
      orderStates: [], 
      // 联系人-列表
      linkManList: [],
      // 业务员数据列表
      serviceManList: [], 
      isMoreOne: "",
      cusOptions: [],
    };
  },
  computed: {
    // 收款总价
    getCollTotalPrice() {
      let rows = this.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        sum += rows[i].price;
      }
      return (sum).toFixed(2);
    },
    // 已收金额
    getalGathPrice() {
      let rows = this.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        sum += rows[i].alGathPrice;
      }
      return (sum).toFixed(2);
    },
    // 旅网总价
    gettravelPrepayPrice() {
      let rows = this.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        sum += rows[i].travelPrepayPrice;
      }
      return (sum).toFixed(2);
    },
    // 自网总价
    getselfPrepayPrice() {
      let rows = this.getSeledRows();

      let sum = 0;
      for (let i = 0; i < rows.length; i++) {
        sum += rows[i].selfPrepayPrice;
      }
      return (sum).toFixed(2);
    },

    /** 获取-订单支付状态 */
    getServiceType() {
      return function (val) {
        switch (val) {
          case "UNPAID":
            return "未付款";
          case "APPLY_SUCCESS":
            return "申请成功";
          case "DEPOSIT_PAID":
            return "已经付定金";
          case "FULL_PAID":
            return "全款已付";
          default:
            return "";
        }
      };
    },
  },
  watch: {
    'dg.selRows': {
      handler(newVal, oldVal){
        console.log('统计金额');
      },
      deep: true
    },
  },
  created() {
    const that = this;

    that.initTbSetData(that.dg.dgName);

    // 取消页面默认查询 2022.3.28
    // that.getDgList();

    that.init();
    that.serState = [
      { id: "COUNTY_SER", name: "县际业务" },
      { id: "CITY_SER", name: "市际业务" },
      { id: "PROVINCE_SER", name: "省际业务" },
    ];
  },
  methods: {
    init() {
      commonSer.getDriverDict({ containLeave: 1, containMain: 0 }).then((res) => {
        this.driverOptions = res.data;
      });
      // 客户（用车方）
      // commonSer.getCompanyCusList({ cusType: "" }).then((res) => {
      //   this.clientList = res.data || [];
      // });
      // 业务员
      commonSer.getStaffCombo({ staffState: "NORMAL,TRY" }).then((res) => {
        this.serviceManList = res.data || [];
      });
      // 供车方单位
      commonSer.getCompanyCusList({ cusType: "CARTEAM" }).then((res) => {
        this.partunitList = res.data || [];
      });
    },
    // 获取-表格数据
    getDgList() {
      const that = this, ps = that.U.scopy(that.dg.ps);

      orderSer.getMainCarOrderForCollection(ps).then(res => {
        if (res.code == 1) {
          let list = res.data;
          list.forEach((it, i) => {
            it.dgName = this.dg.dgName;

            it.sd = it.stime.split(" ")[0];
            it.st = it.stime.split(" ")[1].substring(0, 5);
            it.ed = it.etime.split(" ")[0];
            it.et = it.etime.split(" ")[1].substring(0, 5);

            it.serviceMan = it.carOrderBase.serviceMan.split("-")[1];

            it.restMoney = Number(it.price) - Number(it.alGathPrice);

            it.customId = (it.carOrderBase.customId && it.carOrderBase.customId.unitName) || "";

            const tipsArr = it.needInfo.split("-");
            it.tips = `${tipsArr[0]}座需要${tipsArr[1]}辆已派${tipsArr[2]}辆`;

            if (it.carOrders) {
              // 所有驾驶员信息
              let allDriverInfo = [];
              // 所有的行程详情
              let allRouteDetail = [];
              // 所有客户备注
              let allCusNote = [];
              // 所有驾驶员备注
              let allDriverNote = [];
              // 所有业务员备注
              let allServiceNote = [];
              it.carOrders.forEach(co => {
                // 获取-所有子单-驾驶员信息
                if(co.disCarId){
                  let driverInfo = {plateNum: co.disCarId.plateNum};
                  if(co.disCarId.mainDriver){// 主驾
                    driverInfo.uname = co.disCarId.mainDriver.uname;
                    driverInfo.realName = co.disCarId.mainDriver.realName;
                    driverInfo.phone = co.disCarId.mainDriver.phone;
                  }else if(co.outDriverInfo){// 外调车驾驶员
                    driverInfo.uname = '';
                    driverInfo.realName = co.outDriverInfo.split(',')[1];
                    driverInfo.phone = co.outDriverInfo.split(',')[0];
                  }
                  allDriverInfo.push(driverInfo);
                }

                // 累加行程详情
                allRouteDetail.push(co.routeDetail.replace(/@/g, ''));
                // 累加客户备注
                allCusNote.push(co.cusNote);
                // 累加驾驶员备注
                allDriverNote.push(co.driverNote);
                // 累加业务员备注
                allServiceNote.push(co.serviceNote); 

              });
              // 设置-所有-驾驶员信息
              it.driverInfo = allDriverInfo;
              // 设置-所有-行程详情
              it.routeDetail = allRouteDetail;
              // 设置-所有-客户备注
              let notesA = [];
              allCusNote.forEach(cn => {
                let ai = notesA.findIndex(ait => ait == cn);
                if(cn && ai == -1) notesA.push(cn);
              });
              it.cusNote = notesA;
              // 设置-所有-驾驶员备注
              let notesB = [];
              allDriverNote.forEach(dn => {
                let bi = notesB.findIndex(bit => bit == dn);
                if(dn && bi == -1) notesB.push(dn);
              });
              it.driverNote = notesB;
              // 设置-所有-业务员备注
              let notesC = [];
              allServiceNote.forEach(sn => {
                let ci = notesC.findIndex(cit => cit == sn);
                if(sn && ci == -1) notesC.push(sn);
              });
              it.serviceNote = notesC;
              
            }

          });
          that.dg.list = list;
          that.dg.total = res.count;
          that.dg.allPrice = res.statics;
        }
      });
    },
    // 订单类型
    getServericTypeText(state) {
      let result = this.serState.find((item) => item.id === state);
      return result.name || "--";
    },
    // 获取-派车状态-描述
    getCarTypeText(val) {
      return {
        PENDING: "待定",
        NOFINISHED_DIS_CAR: "已派车未派完",
        FINISHED_DIS_CAR: "已完成派车",
        DELETE: "已删除",
        NOT_DIS_CAR: "未派车",
      }[val];
    },
    // 获取-锁定状态-描述
    getLockText(data) {
      let state = {
        UNLOCK: "未锁定",
        LOCKED: "已锁定",
      };
      return state[data] || "--";
    },

    // 查询-用车单位数据
    queryCusPageList(query) {
      if (!query) return (this.cusOptions = []);
      
      commonSer.queryComboCusPageList({ find: query }).then((res) => {
        if(res.code == 1) this.cusOptions = res.data;
      });
    },
    // 根据用车单位获取联系人列表
    queryLinkManList(obj){
      if(obj.dutyService){
        let arr = [];
        obj.dutyService.split(',').forEach(it => {
          arr.push({
            uname: it.split('-')[0], 
            realName: it.split('-')[1], 
            phone: it.split('-')[2]
          });
        });
        this.linkManList = arr;

        // 默认选择
        if(this.linkManList.length == 1) this.dg.ps.dutyService = this.linkManList[0].uname;
      }else{
        this.dg.ps.dutyService = '';
        this.linkManList = [];
      }
    },

    // 显示/隐藏-收业务款-弹框
    setBusinessCollectionMd(e) {
      const that = this, U = that.U, rows = that.getSeledRows(), md = that.businessCollectionMd;

      if(!e.state){
        md.state = false;
        md.obj = null;
      }else{
        if(rows.length == 0){
          U.qerror(`请至少选择一个订单进行确认收款`);
        }else{
          if(rows.length == 1){
            that.isMoreOne = "more";
          }else if(rows.length > 1){
            that.isMoreOne = "one";
          }

          md.obj = rows;
          md.isMoreOne = that.isMoreOne;
          md.state = true;
        }
      }
    },

    // 显示/隐藏-平账-弹框
    setBackPaymentMd(e) {
      const that = this, U = that.U, rows = that.getSeledRows(), md = that.backPaymentMd;

      if(!e.state){// 关闭弹框
        md.state = false;
      }else{// 开启弹框
        if (!rows || rows.length < 2) return U.qerror("请至少选择2条数据进行平账");

        // 判断是否为同一用户
        let isUnique = true, cusId = null;
        for(let i = 0; i < rows.length; i++){
          let it = rows[i];
          if(i == 0) {
            cusId = it.carOrderBase.customId.id;
          }else if(cusId != it.carOrderBase.customId.id){
            isUnique = false;
            break;
          }
        }
        if (!isUnique) return U.qerror("请选同一用户进行平账");

        // 必须有正数和负数
        let isMinus = rows.some((item) => item.restMoney < 0);
        let isPositive = rows.some((item) => item.restMoney >= 0);
        if (!isMinus || !isPositive) return U.qerror("需要存在有多收金额的订单");

        md.data = rows;
        md.state = true;
      }
    },

    // 显示/隐藏-撤销平账-弹框
    setCancelBackPaymentMd(e) {
      const that = this, U = that.U, rows = that.getSeledRows(), md = that.cancelBackPaymentMd;

      if(!e.state){
        md.state = false;
        md.obj = null;
      }else{
        if(rows.length == 0){
          U.qerror(`请至少选择一个订单数据`);
        }else{
          md.list = rows;
          md.state = true;
        }
      }
    },

    // 导出excel
    handleExport() {
      let that = this, U = that.U, ps = U.scopy(that.dg.ps);

      ps.rows = that.dg.total;
      orderSer.serviveGathExport(ps).then((res) => {
        if (res.code !== 1) {
          U.qerror(res.msg);
        }else{
          exportExcel({
            filename: "业务收款",
            data: res.data,
            enumData: {
              orderNum: "主订单编号",
              status: "用车状态",
              drivers: "驾驶员",
              plateNums: "车牌号",
              sdate: "开始日期",
              stime: "开始时间",
              edate: "结束日期",
              etime: "结束时间",
              serviceMan: "业务员",
              customId: "客户",
              cusNote: "客户备注",
              driverNote: "驾驶员备注",
              routeDetail: "行程详情",
              needCars: "车辆数",
              needInfo: "实派车",
              otherPrice: "其他费用",
              remDriverCharge: "提醒现收",
              price: "收款价格",
              alGathPrice: "已收金额(元)",
              travelPrepayPrice: "旅网金额",
              selfPrepayPrice: "自网金额",
              shouldGath: "应收余额",
              serviceType: "业务类型",
              payStatus: "订单支付状态",
              gathLock: "收款锁定",
              operMark: "操作编号",
              isSplit: "是否拆分",
              operNote: "操作备注",
              routeLink: "行程联系人",

              // addTime: "添加时间",
              // handSelPrice: "派单定金",
              // unitNum: "单位编号",
              // routeName: "团号",
              // orderSource: "订单来源",
              // isSettle: "结算状态",
              // dutyBaseUser: "客户操作员",
            },
          });
        }
      });
    },
    // 取消收款锁定
    cancelConfirmCollection() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length !== 1) {
        U.qerror("请选择一个订单");
      }else{
        let row = rows[0];
        if (!row.gathLock || row.gathLock === "UNLOCK") {
          U.qerror("该订单未被锁定，请重新选择！");
        }else{
          orderSer.cancelConfirmCollection({ id: row.id }).then((res) => {
            if (res.code !== 1) {
              U.qerror(res.msg);
            }else{
              U.qsuccess(res.msg);

              that.getDgList();
            }
          });
        }
      }
    },
    // 显示/隐藏-收款记录-弹框
    setCollectionRecordMd(e) {
      const that = this, U = that.U, rows = that.getSeledRows(), md = that.collectionRecordMd;

      if(!e.state){
        md.state = false;
      }else{
        if (rows.length !== 1){
          U.qerror("请选择一个订单进行撤消收款");
        }else{
          let row = rows[0];
          if(row.payStatus != 'DEPOSIT_PAID' && row.payStatus != 'FULL_PAID'){
            U.qerror("所选订单未业务收款，无法进行撤消收款");
          }else{
            // 弹框获取所选订单的收款记录
            md.obj = row;
            md.state = true;
          }
        }
      }

      // } if (!!selRows[0].operMark) {
      //   U.qerror("operMark为空，无法进行撤消收款");
      // }else{
      //   let ps = { cancelOffSetNum: selRows[0].operMark };
      //   orderSer.cancelOffSet(ps).then((res) => {
      //     if (res.code !== 1) {
      //       U.qerror(res.msg);
      //     }else{
      //       U.qsuccess(res.msg);

      //       that.getDgList();
      //     }
      //   });
      // }
    },
    


  },
};
</script>